package com.htc.android.footprints.service;

import java.util.ArrayList;
import java.util.Iterator;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import com.htc.android.footprints.ILocationAgentCallback;
import com.htc.android.footprints.ILocationAgentService;

public class LocationAgentService extends Service
{
  private static final int HANDLER_SHUTDOWN_AGENT = 100;
  private static final int MODE_FIX_GPS = 13;
  private static final int MODE_FIX_NETWORK = 14;
  private static final int MODE_STOP = 10;
  private static final int MODE_TIMEOUT = 12;
  private static final int MODE_TRACKING = 11;
  private static final String TAG = "LocationAgentService";
  private ArrayList<ILocationAgentCallback> clientList = new ArrayList();
  private LocationAgent mAgent;
  private final ILocationAgentService.Stub mBinder = new ILocationAgentService.Stub()
  {
    public void continueTracking()
      throws RemoteException
    {
      Log.d("LocationAgentService", "continueTracking");
      LocationAgentService.this.mAgent.continueTracking();
    }

    public void enableMyLocation()
      throws RemoteException
    {
      Log.i("LocationAgentService", "enableMyLocation, mAgent = " + LocationAgentService.this.mAgent);
      LocationAgentService.this.mAgent.enableMyLocation();
    }

    public boolean isTimeout()
      throws RemoteException
    {
      Log.d("LocationAgentService", "isTimeout");
      return LocationAgentService.this.mAgent.isTrackingTimeout();
    }

    public boolean isTracking()
      throws RemoteException
    {
      Log.d("LocationAgentService", "isTracking");
      return LocationAgentService.this.mAgent.isTrackingGps();
    }

    public void registerCallback(ILocationAgentCallback paramILocationAgentCallback)
      throws RemoteException
    {
      Log.w("LocationAgentService", "registerCallback, callback = " + paramILocationAgentCallback);
      LocationAgentService.this.clientList.add(paramILocationAgentCallback);
    }

    public boolean removeCallback(ILocationAgentCallback paramILocationAgentCallback)
      throws RemoteException
    {
      Log.w("LocationAgentService", "removeCallback, callback = " + paramILocationAgentCallback);
      return LocationAgentService.this.clientList.remove(paramILocationAgentCallback);
    }

    public void resume()
      throws RemoteException
    {
      LocationAgentService.this.mAgent.resume();
    }

    public void setTimeout(long paramLong)
      throws RemoteException
    {
      Log.d("LocationAgentService", "setTimeout");
      LocationAgentService.this.mAgent.setTimeout(Long.valueOf(paramLong));
    }

    public void setTimeoutNotify(boolean paramBoolean)
      throws RemoteException
    {
      Log.d("LocationAgentService", "setTimeoutNotify");
      LocationAgentService.this.mAgent.setTimeoutNotify(paramBoolean);
    }

    public void shutdownAgent()
      throws RemoteException
    {
      Log.d("LocationAgentService", "shutdownAgent");
      LocationAgentService.this.mAgent.shutdownAgent();
    }

    public void stopTracking()
      throws RemoteException
    {
      Log.d("LocationAgentService", "stopTracking");
      LocationAgentService.this.mAgent.stopTracking();
    }

    public void stopTrackingWithoutNotify()
      throws RemoteException
    {
      Log.d("LocationAgentService", "stopTrackingWithoutNotify");
      LocationAgentService.this.mAgent.stopTrackingWithoutNotify();
    }

    public void waitForPause()
      throws RemoteException
    {
      Log.d("LocationAgentService", "waitForPause");
      LocationAgentService.this.mAgent.waitForPause();
    }
  };

  public LocationAgentService()
  {
    Log.v("LocationAgentService", "LocationAgentService CTOR");
  }

  public IBinder onBind(Intent paramIntent)
  {
    Log.v("LocationAgentService", "Service onBind");
    return this.mBinder;
  }

  public void onCreate()
  {
    super.onCreate();
    Log.v("LocationAgentService", "Service onCreate");
    this.mAgent = LocationAgent.instance(getApplicationContext());
    this.mAgent.setAgentListener(new LocationAgent.AgentListener()
    {
      public void onAgentPause()
      {
        Iterator localIterator = LocationAgentService.this.clientList.iterator();
        while (localIterator.hasNext())
        {
          ILocationAgentCallback localILocationAgentCallback = (ILocationAgentCallback)localIterator.next();
          Log.d("LocationAgentService", "client callback = " + localILocationAgentCallback);
          try
          {
            localILocationAgentCallback.onAgentPause();
          }
          catch (RemoteException localRemoteException)
          {
            localRemoteException.printStackTrace();
          }
        }
      }

      public void onUpdateStatus(int paramInt1, int paramInt2, double paramDouble1, double paramDouble2)
      {
        if (LocationAgentService.this.clientList.size() == 0)
          if (((paramInt1 != 12) && (paramInt1 != 10) && (paramInt1 != 13)) || (LocationAgentService.this.mBinder == null));
        while (true)
        {
          try
          {
            LocationAgentService.this.mBinder.stopTrackingWithoutNotify();
            return;
          }
          catch (RemoteException localRemoteException2)
          {
            localRemoteException2.printStackTrace();
            continue;
          }
          Iterator localIterator = LocationAgentService.this.clientList.iterator();
          while (localIterator.hasNext())
          {
            ILocationAgentCallback localILocationAgentCallback = (ILocationAgentCallback)localIterator.next();
            Log.d("LocationAgentService", "client callback = " + localILocationAgentCallback);
            try
            {
              localILocationAgentCallback.onUpdateStatus(paramInt1, paramInt2, paramDouble1, paramDouble2);
            }
            catch (RemoteException localRemoteException1)
            {
              localRemoteException1.printStackTrace();
            }
          }
        }
      }
    });
  }

  public void onDestroy()
  {
    Log.v("LocationAgentService", "Service onDestroy");
    this.clientList.clear();
    super.onDestroy();
  }
}

/* Location:           E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name:     com.htc.android.footprints.service.LocationAgentService
 * JD-Core Version:    0.6.0
 */